package com.stropheware.droidDefense;

import com.stropheware.droidDefense.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnClickListener{
	
	/*
	 * Flag used to indicate whether in about activity or not
	 * Used to continue playing music while in about activity
	 */

	private static boolean inAboutFlag = false;
	
	public static final boolean DEBUG = true;
	
	private GameAudioManager gameAudioManager;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	requestWindowFeature(Window.FEATURE_NO_TITLE);
    	
        //Forces landscape mode
    	initWindow();
        setContentView(R.layout.main);
        
        // Set up click listeners for all the buttons
        View newButton = findViewById(R.id.new_button);
        newButton.setOnClickListener(this);
        View continueButton = findViewById(R.id.continue_game_button);
        continueButton.setOnClickListener(this);
        View aboutButton = findViewById(R.id.about_button);
        aboutButton.setOnClickListener(this);  
        
        gameAudioManager = new GameAudioManager(this);
        gameAudioManager.addGameAudio(new GameAudio("ambient_menu", R.raw.spaceinvaders, true, this));
        gameAudioManager.playAllAudio();
    }
    
    private void initWindow() {
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	}
    
    @Override
    public void onResume() {
    	super.onResume();
    	gameAudioManager.playAllAudio();
    	inAboutFlag = false;
    }
    
    @Override
    public void onPause() {
    	super.onPause();
    	if(!inAboutFlag) gameAudioManager.pauseAllAudio();
    }
    
    
    public boolean onCreateOptionsMenu(Menu menu){
    	super.onCreateOptionsMenu(menu);
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.testmenu, menu);
    	return true;
    }
    
    public void onClick(View v) {
    	switch (v.getId()) {
	    	case R.id.new_button:
	    		Intent newGame = new Intent(this, GameActivity.class);
	    		startActivity(newGame);
	    		break;
	    	case R.id.continue_game_button:
	    		break;
	    	case R.id.about_button:
	    		inAboutFlag = true;
	         	Intent i = new Intent(this, AboutActivity.class);
	        	startActivity(i);
	        	break;
    	}
    }
       
  }